Skip to content

fix(jaxrs-spec): generate @Deprecated annotations (fixes #18941)#23651

Merged
wing328 merged 3 commits intoOpenAPITools:masterfrom
anna-megalou:fix/jaxrs-spec-deprecated-annotation
Apr 30, 2026
Merged

fix(jaxrs-spec): generate @Deprecated annotations (fixes #18941)#23651
wing328 merged 3 commits intoOpenAPITools:masterfrom
anna-megalou:fix/jaxrs-spec-deprecated-annotation

Conversation

@anna-megalou
Copy link
Copy Markdown
Contributor

@anna-megalou anna-megalou commented Apr 28, 2026

Summary

Adds support for OpenAPI deprecated: true in the jaxrs-spec Java generator.

This PR adds generated Java deprecation annotations where applicable, including:

  • @Deprecated
  • /** @deprecated */
  • deprecated = true in API documentation annotations

It also adds a test for deprecated operations and parameters.

Why

Fixes #18941.

The generated Java code should reflect deprecated operations and parameters from the OpenAPI specification.

How to test

./mvnw -pl modules/openapi-generator test -Dtest=JavaJAXRSSpecServerCodegenTest

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds `@Deprecated` and `deprecated = true` throughout `jaxrs-spec` when the spec marks operations, parameters, models, or fields as deprecated. Aligns generated Java and Javadoc with the OpenAPI spec and adds tests.

- **Bug Fixes**
  - Apply `@Deprecated` and Javadoc `@deprecated` to operations (interface methods) and all parameter types (body, cookie, header, path, query, form), including Quarkus templates.
  - Set `deprecated = true` in Swagger v3 `@Operation` and MicroProfile `@Operation`/`@Schema` (not in Swagger v2 `@ApiOperation`).
  - Propagate deprecation to enums, model classes, properties, getters/setters, collection helpers (add/remove/put/remove), and builder methods.
  - Add tests verifying deprecations in generated `Pet` and `PetApi` (methods and parameters).

<sup>Written for commit 684d56eaa1ac46a2281707e3968a3a83dfe713f8. Summary will update on new commits. <a href="https://cubic.dev/pr/OpenAPITools/openapi-generator/pull/23651?utm_source=github">Review in cubic</a></sup>

<!-- End of auto-generated description by cubic. -->

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 13 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/resources/JavaJaxRS/spec/apiMethod.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/JavaJaxRS/spec/apiMethod.mustache:8">
P1: `@ApiOperation` in Swagger 1.x does not support a `deprecated` attribute, so this newly generated argument can cause compile errors with supported/sample swagger-annotations versions.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread modules/openapi-generator/src/main/resources/JavaJaxRS/spec/apiMethod.mustache Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java:1341">
P2: The test no longer verifies the generated API annotation still includes `deprecated = true`, so a regression in the actual `@Operation` output would pass unnoticed.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


Path petApi = output.toPath().resolve("src/gen/java/org/openapitools/api/PetApi.java");
JavaFileAssert.assertThat(petApi).assertMethod("findPetsByTags", "List<String>").hasAnnotation("Deprecated");
JavaFileAssert.assertThat(petApi).fileContains("* @deprecated", "findPetsByTags");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The test no longer verifies the generated API annotation still includes deprecated = true, so a regression in the actual @Operation output would pass unnoticed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java, line 1341:

<comment>The test no longer verifies the generated API annotation still includes `deprecated = true`, so a regression in the actual `@Operation` output would pass unnoticed.</comment>

<file context>
@@ -1338,7 +1338,7 @@ public void generatesDeprecatedAnnotationsForModelsOperationsAndParameters_issue
         Path petApi = output.toPath().resolve("src/gen/java/org/openapitools/api/PetApi.java");
         JavaFileAssert.assertThat(petApi).assertMethod("findPetsByTags", "List<String>").hasAnnotation("Deprecated");
-        JavaFileAssert.assertThat(petApi).fileContains("@ApiOperation", "deprecated = true", "findPetsByTags");
+        JavaFileAssert.assertThat(petApi).fileContains("* @deprecated", "findPetsByTags");
         JavaFileAssert.assertThat(petApi).fileContains("findPetsByStatus", "@Deprecated", "@QueryParam(\"status\")");
     }
</file context>
Suggested change
JavaFileAssert.assertThat(petApi).fileContains("* @deprecated", "findPetsByTags");
JavaFileAssert.assertThat(petApi).fileContains("@Operation", "deprecated = true", "findPetsByTags");

@wing328
Copy link
Copy Markdown
Member

wing328 commented Apr 29, 2026

thanks for the pr

please follow step 3 to update the samples

@wing328 wing328 merged commit 8a65919 into OpenAPITools:master Apr 30, 2026
37 checks passed
@wing328 wing328 added this to the 7.23.0 milestone Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [jaxrs-spec] Not generating @Deprecated annotations

2 participants